package interf2;

import java.util.Comparator;

class DogCompareX implements Comparator {
	public int compare(Object arg0, Object arg1) {
		Dog d1 = (Dog) arg0;
		Dog d2 = (Dog) arg1;

		if (d1.getX() > d2.getX())
			return +1;

		if (d1.getX() < d2.getX())
			return -1;

		return 0;
	}
}

class DogCompareY implements Comparator {
	public int compare(Object arg0, Object arg1) {
		Dog d1 = (Dog) arg0;
		Dog d2 = (Dog) arg1;

		if (d1.getY() > d2.getY())
			return +1;

		if (d1.getY() < d2.getY())
			return -1;

		return 0;
	}
}

public class Comparing3 {
	public static void main(String[] args) {
		Dog a = new Dog(4, 5.0);
		Dog b = new Dog(7, 3.2);

		System.out.println(" a is " + a);
		System.out.println(" b is " + b);

		DogCompareX cx = new DogCompareX();

		System.out.println("Comparing x components:");
		System.out.println("  a and b: " + cx.compare(a, b));
		System.out.println("  b and a: " + cx.compare(b, a));
		System.out.println("  a and a: " + cx.compare(a, a));
		System.out.println("  b and b: " + cx.compare(b, b));

		DogCompareY cy = new DogCompareY();

		System.out.println("Comparing y components:");
		System.out.println("  a and b: " + cy.compare(a, b));
		System.out.println("  b and a: " + cy.compare(b, a));
		System.out.println("  a and a: " + cy.compare(a, a));
		System.out.println("  b and b: " + cy.compare(b, b));
	}
}